﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Domain.MainModule.Entities;
using Infraestructure.Data.MainModule.UnitOfWork;
using Infraestructure.CrossCutting.Logging;
using Domain.MainModule.Branches;
using Infraestructure.Data.MainModule.Repositories;

namespace Infraestructure.Data.MainModule.Tests.RepositoriesTests
{
    [TestClass()]
    public class BranchRepositoryTest : RepositoryTestsBase<Branch>
    {
       public override System.Linq.Expressions.Expression<Func<Branch, bool>> FilterExpression
        {
            get { return a => a.BranchId == TestConstants.Instance.BRANCH_ID; }
        }

        public override System.Linq.Expressions.Expression<Func<Branch, Guid>> OrderByExpression
        {
            get { return a => a.BranchId; }
        }
		
		[TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void FindBranch_Invoke_NullSpecThrowNewArgumentNullException_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IBranchRepository repository = new BranchRepository(context, traceManager);

            //Act
            repository.FindBranch(null);
        }

        #region BranchBranchIdSpecification
			
		[TestMethod()]
        public void FindBranch_Invoke_InvalidBranchIdReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IBranchRepository repository = new BranchRepository(context, traceManager);

			Guid invalidId = new Guid("11111111-1111-1111-1111-111111111111");
            BranchBranchIdSpecification spec = new BranchBranchIdSpecification(invalidId);

            //Act
            Branch Branch = repository.FindBranch(spec);

            //Assert
            Assert.IsNull(Branch);
        }

		
        [TestMethod()]
        public void FindBranchById_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IBranchRepository repository = new BranchRepository(context, traceManager);

            BranchBranchIdSpecification spec = new BranchBranchIdSpecification(TestConstants.Instance.BRANCH_ID);

            //Act
            Branch Branch = repository.FindBranch(spec);

            //Assert
            Assert.IsNotNull(Branch);
        }

        #endregion

        #region BranchGroupBranchIdSpecification

        [TestMethod()]
        public void FindBranch_Invoke_InvalidGroupBranchIdReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IBranchRepository repository = new BranchRepository(context, traceManager);

			Guid invalidId = new Guid("11111111-1111-1111-1111-111111111111");
            BranchGroupBranchIdSpecification spec = new BranchGroupBranchIdSpecification(invalidId);

            //Act
            Branch Branch = repository.FindBranch(spec);

            //Assert
            Assert.IsNull(Branch);
        }

        [TestMethod()]
        public void FindBranchByGroupBranchId_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IBranchRepository repository = new BranchRepository(context, traceManager);

            BranchGroupBranchIdSpecification spec = new BranchGroupBranchIdSpecification(TestConstants.Instance.GROUP_BRANCH_ID);

            //Act
            IEnumerable<Branch> result = repository.FindBranches(spec);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count() > 0);
        }

        #endregion
    }
}
